package top.jsjkxyjs.blackbox.BigData;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Objects;

public class IotData implements WritableComparable<IotData> {
    private String at;
    private String type;
    private String ds_id;
    private String value;
    private String dev_id;

    public IotData() {
    }

    public IotData(String at, String type, String ds_id, String value, String dev_id) {
        this.at = at;
        this.type = type;
        this.ds_id = ds_id;
        this.value = value;
        this.dev_id = dev_id;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        IotData iotData = (IotData) o;
        return Objects.equals(at, iotData.at) && Objects.equals(type, iotData.type) && Objects.equals(ds_id, iotData.ds_id) && Objects.equals(value, iotData.value) && Objects.equals(dev_id, iotData.dev_id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(at, type, ds_id, value, dev_id);
    }

    @Override
    public String toString() {
        return at + "\t" + type + "\t" + ds_id + "\t" + value + "\t" + dev_id;

    }

    public String getAt() {
        return at;
    }

    public void setAt(String at) {
        this.at = at;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getDs_id() {
        return ds_id;
    }

    public void setDs_id(String ds_id) {
        this.ds_id = ds_id;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getDev_id() {
        return dev_id;
    }

    public void setDev_id(String dev_id) {
        this.dev_id = dev_id;
    }


    @Override
    public int compareTo(IotData o) {
        return at.compareTo(o.getAt());
    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(at);
        dataOutput.writeUTF(type);
        dataOutput.writeUTF(ds_id);
        dataOutput.writeUTF(value);
        dataOutput.writeUTF(dev_id);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {

        this.at = dataInput.readUTF();
        this.type = dataInput.readUTF();
        this.ds_id = dataInput.readUTF();
        this.value = dataInput.readUTF();
        this.dev_id = dataInput.readUTF();
    }
}
